<%@ page import="cn.school.vo.Page" %>
<%@ page import="javax.rmi.CORBA.Stub" %>
<%@ page import="cn.school.entity.Student" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <script src="js/jquery-3.4.1.min.js"></script>
    <script>
        $(function () {
            $("table tr:odd").css("background-color", "brown");
            $("input#go").click(function () {
                var $p = $(this).prev().val();
                window.location.href = 'studentServlet?pageNo=' + $p;
            });
            $("#pager a.first").click(function () {
                $("form [name=pageNo]").val(1);
                $("form").submit();
                return false;
            });

            $("#pager a.next,#pager a.prev,#pager a.last").click(function () {
                $("form [name=pageNo]").val($(this).attr("data-page"));
                $("form").submit();
                return false;
            });
        });
    </script>
</head>
<body>
<%-- 翻译成java的时候，合并成一个java类 --%>
<%--<%@include file="/WEB-INF/checkLogin.jsp"%>--%>

<h2>学生信息</h2>
<div>
    <form action="studentServlet">
        <input type="hidden" name="pageNo" value="1"/>
        <input type="search" name="sname" placeholder="姓名" value="${sname}"/>
        <input type="search" name="qq" placeholder="QQ" value="${qq}"/>
        <input type="search" name="phone" placeholder="手机号" value="${phone}"/>
        <input type="submit" value="搜索"/>
        <input type="button" value="新生注册" onclick="window.location='toAddStudentServlet'"/>
    </form>
</div>
<%
    Page<Student> p=(Page<Student>)request.getAttribute("p");
%>
<table border="1" cellspacing="0" cellpadding="0">
    <tr bgcolor="#a9a9a9">
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>手机号</th>
        <th>QQ</th>
        <th>入学时间</th>
        <th>操作</th>
    </tr>

    <%
        for(Student s:p.getData()){
    %>
    <tr>
        <td><%=s.getStuno()%>
        </td>
        <td><%=s.getSname()%>
        </td>
        <td><%=s.getSex()%>
        </td>
        <td><%=s.getTelephone()%>
        </td>
        <td><%=s.getQq()%>
        </td>
        <td>
            <%=s.getEnterdate()%>
        </td>
        <td><a href="toUpdateStudent?stuno=<%=s.getStuno()%>">修改</a> 删除,<a href="findStudentScore?stuno=${stu.stuno}">查看成绩</a> </td>
    </tr>
    <%}%>
</table>
<p align="center" id="pager">
    <a href="studentServlet?pageNo=1" class="first" data-page="1">第一页</a>

    <c:if test="${p.pageNo>1}">
    <a href="studentServlet?pageNo=${p.pageNo-1}" class="prev" data-page="${p.pageNo-1}">上一页</a>
    </c:if>
    <input type="number" min="1" value="${p.pageNo}" style="width: 40px"/>/${p.totalPages}
    <input type="button" value="电梯直达" id="go"/>

    <c:if test="${p.pageNo<p.totalPages}">
    <a href="studentServlet?pageNo=${p.pageNo+1}" class="next" data-page="${p.pageNo+1}">下一页</a>
    </c:if>
    <a href="studentServlet?pageNo=${p.totalPages}" class="last" data-page="${p.totalPages}">最后一页</a>
</p>
</body>
</html>
